package com.titanium.client.Titanium.Media;

public class Sound 
{
	public Sound(String path)
	{
		if (!this._init)
		{
			SoundJSNI.initMediaSound();
			this._init = true;
		}
		
		this._soundId = "sound" + this._soundCount++;
		SoundJSNI.createSound(path, this._soundId);	
	}
	
	/**
	 * Return the current volume of this Media.Sound object. Volume values will be between 0.0 and 1.0.
	 * @return
	 */
	public double getVolume()
	{
		double volume = 0.0;
		volume = SoundJSNI.getVolume(this._soundId) / 100;
		return volume;
	}
	
	/**
	 * Return true if this Media.Sound is set to loop and false otherwise.
	 * @return
	 */
	public boolean isLooping()
	{
		return SoundJSNI.isLooping(this._soundId);
	}
	
	/**
	 * Return true if this Media.Sound is paused and false otherwise.
	 * @return
	 */
	public boolean isPaused()
	{
		return SoundJSNI.isPaused(this._soundId);
	}
	
	/**
	 * Return true if this Media.Sound is playing and false otherwise.
	 * @return
	 */
	public boolean isPlaying()
	{
		return SoundJSNI.isPlaying(this._soundId);
	}
	
	/**
	 * Pause a currently playing sound.
	 */
	public void pause()
	{
		SoundJSNI.pause(this._soundId);
	}
	
	/**
	 * Play a sound object. If the sound is paused, it will resume from the current location.
	 */
	public void play()
	{
		SoundJSNI.play(this._soundId);
	}
	
	/**
	 * Reload this sound from the original URL or path.
	 */
	public void reload()
	{
		SoundJSNI.reload(this._soundId);
	}
	
	/**
	 * Set whether or not this sound should loop.
	 */
	public void setLooping(boolean shouldLoop)
	{
		SoundJSNI.setLooping(this._soundId, shouldLoop);
	}
	
	/**
	 * Set whether or not this sound should loop.
	 */
	public void setVolume(double volume)
	{
		volume = Math.floor(volume * 100);
		String vol = volume + "";
		SoundJSNI.setVolume(this._soundId, vol);
	}
	
	
	private String 			_soundId;
	
	protected static int	 _soundCount = 0;
	protected static boolean _init = false;
}
